package com.bsoft.template.service.process;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bsoft.template.entity.process.Process;
import com.bsoft.template.mapper.process.ProcessMapper;
import com.bsoft.template.service.base.BaseServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcessService extends BaseServiceImpl<ProcessMapper, Process> {

    public Process getProcessByRole(String roleCode) {
        QueryWrapper<Process> wrapper = new QueryWrapper<>();
        wrapper.eq("role", roleCode);
        return baseMapper.selectOne(wrapper);
    }

    public List<Process> getProcessList() {
        QueryWrapper<Process> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("sort");
        List<Process> processes = baseMapper.selectList(wrapper);
        return processes;
    }

    public Process getFirstStep() {
        return getProcessList().get(0);
    }

    public Process getLastStep() {
        List<Process> processes = getProcessList();
        return processes.get(processes.size() - 1);
    }
}
